package com.saile.service;

import com.saile.dao.AdvertMapper;
import com.saile.domain.Advert;
import com.saile.myRunTime.MyRunTimeExcption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2018-4-24.
 */
@Service
public class AdvertServiceImpl extends BaseService implements AdvertService {
    @Autowired
    AdvertMapper advertMapper;


    private void insertAdvert(Advert advert) {
        advertMapper.insertAdvert(advert);
    }

    private void updateAdvert(Advert advert) {
        advertMapper.updateAdvertByPrimaryKeySelective(advert);
    }

    @Override
    public void modifyAdvert(Advert advert) throws MyRunTimeExcption {
        if (advert.getTid() == null) {
            insertAdvert(advert);
            return;
        }
        updateAdvert(advert);

    }

    @Override
    public void deleteAdvert(Long advertId) throws MyRunTimeExcption {
        advertMapper.deleteAdvert(advertId);
    }

    @Override
    public List<Advert> getAdvertList(Map<String, String> map) throws MyRunTimeExcption {
        return advertMapper.getAdvertList(map);
    }

    @Override
    public Advert getAdvert(Map<String, String> map) throws MyRunTimeExcption {
        return advertMapper.getAdvert(map);
    }
}
